package com.hl.card.modular.pack.service.impl;

import com.hl.card.common.util.DateUtils;
import com.hl.card.common.util.ResponseData;
import com.hl.card.modular.pack.dao.DisMemberApplyMapper;
import com.hl.card.modular.pack.dao.DisMemberProcessMapper;
import com.hl.card.modular.pack.model.DisMemberApplyModel;
import com.hl.card.modular.pack.model.DisMemberProcessModel;
import com.hl.card.modular.pack.service.DisMemberProcessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 合伙人申请服务层
 * @author 袁伟
 *
 */
@Service
public class DisMemberProcessServiceImpl  implements DisMemberProcessService{
	@Autowired
	private DisMemberProcessMapper disMemberProcessMapper;
	@Autowired
	private ResponseData responseData;
	@Autowired
	private DisMemberApplyMapper disMemberApplyMapper;
	@Resource
	private RedisTemplate<String,Object> redisTemplate;
	
	@Override
	public ResponseData searchDisMemberProcess(String user_id) {
		List<DisMemberProcessModel> processList=disMemberProcessMapper.searchDisMemberProcess(user_id);
	    boolean  result=redisTemplate.hasKey("company_address");
	    String address="";
	    if(result)
	    {
	    	address=redisTemplate.opsForValue().get("company_address")+"";
	    }else
	    {
	    	redisTemplate.opsForValue().set("company_address", "广东省深圳市福田区天安数码大厦A座");
	    	address="广东省深圳市福田区天安数码大厦A座";
	    }
	    Map<String,Object> map=new HashMap<String, Object>();
	    map.put("address", address);
	    map.put("data", processList);
		responseData.setData(map);
		responseData.setStatus("1");
		responseData.setMsg("操作成功");
		return responseData;
	}

	@Override
	public ResponseData addLogisticsInfo(String r_logistics_company, String r_logistics_no, String user_id) {
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("user_id", user_id);
		map.put("status", 4);
		DisMemberProcessModel searchDisMemberProcess=disMemberProcessMapper.searchDisMemberProcessByStatus(map);
		if(searchDisMemberProcess!=null)
		{
			responseData.setData(null);
			responseData.setStatus("0");
			responseData.setMsg("请勿重复操作");
			return responseData;
		}
		DisMemberApplyModel disMemberApply=new DisMemberApplyModel();
		disMemberApply.setR_logistics_company(r_logistics_company);
		disMemberApply.setR_logistics_no(r_logistics_no);
		disMemberApplyMapper.updateDisMemberApply(disMemberApply);
		DisMemberProcessModel disMemberProcess=new DisMemberProcessModel();
		disMemberProcess.setContent("回寄签约合同");
		disMemberProcess.setTime(DateUtils.getNow());
		disMemberProcess.setUser_id(user_id);
		disMemberProcess.setStatus(4);
		disMemberProcessMapper.addDisMemberProcess(disMemberProcess);
		responseData.setData(null);
		responseData.setStatus("1");
		responseData.setMsg("操作成功");
		return responseData;
	}
	

	

}

